package cn.xuewenbao.edu.controller;


import cn.xuewenbao.edu.entity.Course;
import cn.xuewenbao.edu.entity.vo.*;
import cn.xuewenbao.edu.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author mafayu
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/edu/course")
@Slf4j
@Api(tags = "课程表")
public class CourseController {

    @Autowired
    private CourseService courseService;

    //根据课程id查询课程基本信息
    @ApiOperation(value = "根据课程id查询课程基本信息")
    @GetMapping("getCourseInfo/{courseId}/{userId}")
    public Result<CourseInfoVo> getCourseInfo(@PathVariable String courseId, @PathVariable String userId) {
        Result<CourseInfoVo> result = courseService.getCourseInfo(courseId, userId);
        return result;
    }

    //获取推荐课程（根据发布时间倒序排列）
    @ApiOperation(value = "获取推荐课程（根据发布时间倒序排列）")
    @GetMapping("getRecommendCourse")
    public Result<List<CourseIndexVo>> getRecommendCourse() {
        Result<List<CourseIndexVo>> result = courseService.getRecommendCourse();
        return result;
    }

    //获取热门课程（根据购买数）
    @ApiOperation(value = "获取热门课程（根据购买数）")
    @GetMapping("getHotCourse")
    public Result<List<CourseIndexVo>> getHotCourse() {
        Result<List<CourseIndexVo>> result = courseService.getHotCourse();
        return result;
    }

    //根据讲师id获取课程列表
    @ApiOperation(value = "根据讲师id获取课程列表")
    @GetMapping("getOwnCourse/{teacherId}")
    public Result<List<CourseIndexVo>> getOwnCourse(@PathVariable String teacherId) {
        Result<List<CourseIndexVo>> result = courseService.getOwnCourse(teacherId);
        return result;
    }

    //添加课程
    @ApiOperation(value = "添加课程")
    @PostMapping("addCourse")
    public Result<?> addCourse(@RequestBody CoursePulishVo coursePulishVo) {
        Result<?> result = courseService.addCourse(coursePulishVo);
        return result;
    }

    //
    //课程最终发布
    //修改课程状态
    @ApiOperation(value = "课程最终发布")
    @PostMapping("publishCourse/{courseId}")
    public Result<Boolean> publishCourse(@PathVariable String courseId) {
        Result<Boolean> result = new Result<>();
        Course course = new Course();
        course.setId(courseId);
        course.setStatus("Normal");
        result.setResult(courseService.updateById(course));
        return result;
    }

    //根据课程id删除课程
    @ApiOperation(value = "根据课程id删除课程")
    @DeleteMapping("deleteCourse/{courseId}")
    public Result<?> deleteCourse(@PathVariable String courseId) {
        Result<?> result = courseService.removeCourse(courseId);
        return result;
    }

    //根据课程id和作者id删除课程
    @ApiOperation(value = "根据课程id和作者id删除课程")
    @DeleteMapping("deleteOwnCourse/{courseId}/{userId}")
    public Result<?> deleteOwnCourse(@PathVariable String courseId,
                                     @PathVariable String userId) {
        Result<?> result = courseService.deleteOwnCourse(courseId,userId);
        return result;
    }

    //根据课程id获取课程购买链接
    @ApiOperation(value = "根据课程id获取课程购买链接")
    @GetMapping("getCourseBuyLink/{courseId}")
    public Result<CourseBuyLink> getCourseBuyLink(@PathVariable String courseId) {
        Result<CourseBuyLink> result = courseService.getCourseBuyLink(courseId);
        return result;
    }
}

